<template>
  <div>
    <div v-if="show" class="cus">
      <div class="cus_box" style="width:1200px;">
        <div class="title">
          <span>已关联设备</span>
          <i @click="show = false" class="el-icon-close"></i>
        </div>
        <div class="mt10">
          <el-button type="primary" @click="add">新增设备</el-button>
        </div>
        <div class="content">
          <el-table :data="tableData" height="500" border style="width: 100%" align="center">
            <el-table-column align="center" prop="id" label="ID" width="180"></el-table-column>
            <el-table-column align="center" prop="sn" label="机柜编号" width="180"></el-table-column>
            <el-table-column align="center" prop="deviceType" label="设备类型" width="180">
              <template slot-scope="scope">
                {{scope.row['deviceType'] == 1?'换电柜':scope.row['deviceType'] == 2?'电动车':scope.row['deviceType'] == 3?'充电柜':'--'}}
              </template>
            </el-table-column>
            <el-table-column align="center" label="二维码">
              <template slot-scope="scope">
                <el-popover placement="right" trigger="hover">
                  <el-image style="width:300px;height:300px;" :src="baseUrl + scope.row.qrCode">
                  </el-image>
                  <el-image slot="reference" :src="baseUrl + scope.row.qrCode"></el-image>
                </el-popover>
              </template>
            </el-table-column>
            <el-table-column align="center" prop="deviceName" label="机柜名称"></el-table-column>
            <el-table-column align="center" prop="address" label="地址"></el-table-column>
            <el-table-column align="center" prop="contacts" label="代理商"></el-table-column>
            <el-table-column align="center" prop="deviceStatus" label="机柜状态" width="140px">
              <!-- 设备状态：1：（在线）运行中 2: 离线 3: 设备故障 -->
              <template slot-scope="scope">
                <span
                  :class="scope.row['deviceStatus'] == 1 ? 'success' : scope.row['deviceStatus'] == 2 ? 'c9' : scope.row['deviceStatus'] == 3 ? 'danger' : ''">
                  {{
										scope.row['deviceStatus'] == 1
											? '（在线）运行中'
											: scope.row['deviceStatus'] == 2
											? '离线'
											: scope.row['deviceStatus'] == 3
											? '设备故障'
											: '--'
									}}
                </span>
              </template>
            </el-table-column>
            <el-table-column align="center" prop="ctime" label="创建时间" width="160"></el-table-column>
            <el-table-column align="center" label="操作">
              <template slot-scope="scope">
                <el-button @click="advertList_cancel(scope.row)" type="text">取消关联</el-button>
              </template>
            </el-table-column>
          </el-table>
        </div>
      </div>
    </div>

    <add ref="add" v-on:add_call="add_call" :addList="tableData"></add>
  </div>
</template>

<script>
import add from './add2'
export default {
  name: 'Related_advertising',
  components: {
    add
  },
  data() {
    return {
      show: false,
      row: {},
      tableData: []
    }
  },
  mounted() { },
  methods: {
    async getData() {
      const res = await this.apis.advertDevice_deviceList({
        pageNum: 1,
        pageSize: 100000,
        abId: this.row.id
      })
      const list = res.rows || []
      this.tableData = list
    },
    fun_show(row) {
      this.row = row
      this.show = true

      this.getData()
    },
    add() {
      this.$refs.add.fun_show(this.row)
    },
    add_call() {
      this.getData()
    },
    advertList_cancel(row) {
      this.$confirm('确定要取消关联吗?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(async () => {
          const res = await this.apis.advertDevice_cancel({
            abId: this.row.id,
            deviceId: row.id
          })
          this.$message({
            type: 'success',
            message: '取消成功!'
          })

          this.getData()
        })
        .catch(() => { })
    }
  }
}
</script>

<style scoped lang="scss"></style>
